Description:
To increase abstraction of your code, you should invoke methods using interfaces and not classes implemented by these interfaces. Therefore, instead of casts to the implementation classes, it is better to cast to the interface defining this method.
Incorrect:
interface IShape {
void draw();
}
class Circle : IShape {
public void draw() {
...
}
}
class View {
void update(Object obj) {
((Circle) obj).draw();
}
}
Correct:
class View {
void update(Object obj) {
((IShape) obj).draw();
}
}